package idv.arthur.JCraft;

import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

public class Exec {
	public static void main(String[] arg) {
		try {
			JSch jsch = new JSch();
			JSch.setConfig("StrictHostKeyChecking", "no");

			String host = "10.144.97.99";
			String user = "root";

			Session session = jsch.getSession(user, host, 22);
			

			// username and password will be given via UserInfo interface.
			session.setPassword("arthur7382");
			session.connect();

			String command = "rm -rf /var/www/svn/Arthur;svnadmin create /var/www/svn/Arthur;chown apache.apache /var/www/svn/Arthur -R";

			Channel channel = session.openChannel("exec");
			((ChannelExec) channel).setCommand(command);
			


			channel.connect();

			/*byte[] tmp = new byte[1024];
			while (true) {
				while (in.available() > 0) {
					int i = in.read(tmp, 0, 1024);
					if (i < 0)
						break;
					System.out.print(new String(tmp, 0, i));
				}
				if (channel.isClosed()) {
					System.out.println("exit-status: "
							+ channel.getExitStatus());
					break;
				}
				try {
					Thread.sleep(1000);
				} catch (Exception ee) {
				}
			}*/
			
			channel.disconnect();
			session.disconnect();
		} catch (Exception e) {
			System.out.println(e);
		}
	}
	
}